<!DOCTYPE html><html><head><title>项目结构分析</title><meta charset='utf-8'><link href='https://cdn.maxiang.io/res-min/themes/marxico.css' rel='stylesheet'><style></style></head><body><div id='preview-contents' class='note-content'>
                        
                    

<div><div class="toc"><div class="toc">
<ul>
<li><a href="#项目结构分析">项目结构分析</a></li>
<li><a href="#main">main</a></li>
<li><a href="#模块">模块</a><ul>
<li><a href="#task模块">task模块</a></li>
<li><a href="#container-容器模块">container 容器模块</a></li>
</ul>
</li>
<li><a href="#service模块">service模块</a></li>
</ul>
</div>
</div>
</div>

<h1 id="项目结构分析">项目结构分析</h1>

<h1 id="main">main</h1>



<pre class="prettyprint hljs-dark"><code class="language-go hljs"><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
</div><div class="hljs-line"><wbr>
</div><div class="hljs-line">    <span class="hljs-comment">// register rpc service  类似生成路由实例</span>
</div><div class="hljs-line">    service.RegisterRpc()
</div><div class="hljs-line"><wbr>
</div><div class="hljs-line">    <span class="hljs-comment">// task worker start 消费者</span>
</div><div class="hljs-line">    <span class="hljs-keyword">go</span> container.NewWorker().StartTask()
</div><div class="hljs-line"><wbr>
</div><div class="hljs-line">    <span class="hljs-comment">// start rpc  server  监听请求</span>
</div><div class="hljs-line">    rpcStartServer()
</div><div class="hljs-line">}
</div></code></pre>

<p><img longdesc="./1568624193085.png" alt="Alt text" title="" type="image/png" src="" class=""></p>

<p>调用端(client)通过RPC方法调用到rpcStartServer监听器,  rpcStartServer解析会转发到RegisterRpc所注册的方法进行处理请求,</p>



<h1 id="模块">模块</h1>



<h2 id="task模块">task模块</h2>

<p><img longdesc="./1568684359206.png" alt="Alt text" title="" type="image/png" src="" class=""></p>

<p>任务模块提供了增删改查方法提供给调用者, 负责执行</p>

<h2 id="container-容器模块">container 容器模块</h2>

<p><img longdesc="./1568684837967.png" alt="Alt text" title="" type="image/png" src="" class=""></p>

<p>Crx负责生成全局单例</p>

<p>Worker负责适配器 调用task模块</p>

<p><img longdesc="./1568698095350.png" alt="Alt text" title="" type="image/png" src="" class=""></p>

<h1 id="service模块">service模块</h1>

<p>定义了三个rpc服务</p>

<p><img longdesc="./1568699679133.png" alt="Alt text" title="" type="image/png" src="" class=""></p>

<p>启动时将这三个服务进行注册</p></div></body></html>